﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Configuration;
using CRMWeb.Utilities.Context;

namespace CRMWeb.Utilities
{
    public class BasePage : System.Web.UI.Page
    {
        public BasePage()
        {
            this.PreInit += new EventHandler(BasePage_PreInit);
            this.Load += new EventHandler(BasePage_Load);
            //this.Error += new EventHandler(MainBasePage_Error);
        }

        protected void BasePage_PreInit(object sender, EventArgs e)
        {  
            // Use https
            if (Convert.ToBoolean(ConfigurationManager.AppSettings["ForceSSL:Enabled"]))
            {
                if (!Request.IsSecureConnection)
                    Response.Redirect(Request.Url.ToString().Replace(Request.Url.Scheme, "https"));
            }

            // Authentication
            if (!CMSContext.IsAuthenticated() && !Request.RawUrl.Contains("/Pages/Login.aspx"))
            {
                Response.Redirect("/Pages/Login.aspx", true);
            }
        }

       

        protected void BasePage_Load(object sender, EventArgs e)
        {
            //Response.Write("BasePage_Load");
        }
    }
}